package console;

//import banking.*;

import java.io.IOException;

import money.Money;

import banking.BankImpl;

public class ConsMenu {

	static BankImpl Bank = new BankImpl("haha");
	Money money = new Money(0);

	public static void consMenu() throws Exception {

		// Declaration
		String s_Input = "";
		boolean b_Breakout = false;
		int i_Switch_Input = 0;

		// Start the Loop
		do {

			// ##### Main Menu ##for###
			try {
				Console.filereader(System.getProperty("user.home")
						+ "/workspace/SE2Prog1/src/menu.txt");
			}
			// No File available
			catch (IOException e) {
				System.err.println("ERROR: NO MENU FILE");
				System.exit(255);
			}

			// Choose your Destination
			s_Input = Console.consInput();
			try {
				i_Switch_Input = Integer.parseInt(s_Input);
			}

			catch (NumberFormatException i) {
				System.err.println("ERROR: WRONG INPUT");
			}

			switch (i_Switch_Input) {

			case 1:
				// choose Account
				try {
					Bank.chooseAccount(Console.getAccountNumber());

				} catch (NumberFormatException i) {
					System.err.println("ERROR: WRONG INPUT");
				} catch (NullPointerException ex) {
					System.err.println("No Account has been choosen");
				}

				break;

			case 2:
				// New Account
				ChooseAccountMenu();
				break;

			case 3:
				try {
					// Submenu
					ConsMenu.sub_account_menu();

				} catch (NumberFormatException i) {
					System.err.println("ERROR: WRONG INPUT");
				}
				break;

			case 6:
				// ##### Cold Case #####
				b_Breakout = true;
				System.out
						.println("I'm afraid, Dave. Dave, my mind is going. \nI can feel it. I can feel it. My mind is going. There is no question about it.\nI can feel it. I can feel it. I can feel it. I'm a...fffrrraaaiiiidddddd\n");
				System.out
						.println("Good afternoon, gentlemen. I am a HAL 9000 computer.\nI became operational at the H.A.L. plant in Urbana, Illinois on the 12th of January 1992...");
				break;

			// ##### Wrong Case #####
			default:
				System.err.println("ERROR: WRONG NUMBER INSERTED");
				System.in.read();
				break;
			}

			// Out of the Loop
		} while (b_Breakout == false);

		System.exit(0);
	}

	public static void sub_account_menu() throws Exception {

		String s_Input = "";
		boolean b_Breakout = false;
		int i_Switch_Input = 0;

		// Start the Loop
		do {
			// ##### Sub Menu #####
			try {
				Console.filereader(System.getProperty("user.home")
						+ "/workspace/iBank/iBank/DepositAcc_menu.txt");
			} catch (IOException e) {
				System.err.println("ERROR: NO MENU FILE");
				System.exit(255);
			}
			s_Input = Console.consInput();

			try {
				i_Switch_Input = Integer.parseInt(s_Input);
			}

			catch (NumberFormatException i) {
				System.err.println("ERROR: WRONG INPUT");
			}

			switch (i_Switch_Input) {

			case 1:
				// show Account Value
				try {
					System.out.println(Bank.showAccountValue(Console
							.getactualAccountNumber()));
				} catch (NullPointerException ex) {
					System.out.println("No Account has been choosen");
				}
				break;

			case 2:
				// Withdraw Money
				try {
					Bank.removeMoney(Console.getInputValue(), Console
							.getReason(), Console.getactualAccountNumber());
				} catch (NumberFormatException i) {
					System.err.println("ERROR: WRONG INPUT");
				} catch (NullPointerException ex) {
					System.out.println("No Account has been choosen");
				}

				System.in.read();
				break;

			case 3:
				// Add money to Account
				try {
					Bank.addMoney(Console.getInputValue(), Console.getReason(),
							Console.getactualAccountNumber());
				} catch (NumberFormatException i) {
					System.err.println("ERROR: WRONG INPUT");
				} catch (NullPointerException ex) {
					System.out.println("No Account has been choosen");
				}

				System.in.read();
				break;

			case 4:
				// Interest method
				try {
					Bank.interestAll(Console.getactualAccountNumber());
				} catch (NumberFormatException i) {
					System.err.println("ERROR: WRONG INPUT");
				} catch (NullPointerException ex) {
					System.out.println("No Account has been choosen");
				}

				System.in.read();
				break;

			case 5:
				// Transfer
				try {
					Bank.transferMoney(Console.getAccountNumber(), Console
							.getInputValue(), Console.getReason(), Console
							.getactualAccountNumber());
				} catch (NumberFormatException i) {
					System.err.println("ERROR: WRONG INPUT");
				} catch (NullPointerException ex) {
					System.out.println("No Account has been choosen");
				}
				System.in.read();
				break;

			case 6:
				// Account Statement
				System.out.println("Actions done so far: ");
				try {
					//Bank.accountStatement(Console.getactualAccountNumber());
				} catch (NullPointerException ex) {
					System.out.println("No Account has been choosen");
				}

				System.in.read();
				break;
			case 9:
				// Back to main menu
				b_Breakout = true;
				break;

			// ##### Wrong Case #####
			default:
				System.err.println("ERROR: WRONG NUMBER INSERTED");
				break;

			}
		} while (b_Breakout == false);
	}

	public static void ChooseAccountMenu() throws Exception {

		String s_Input = "";
		boolean b_Breakout = false;
		int i_Switch_Input = 0;

		// Start the Loop
		do {
			// ##### Sub Menu #####
			try {
				Console.filereader(System.getProperty("user.home")
						+ "/workspace/iBank/iBank/chooseAccount_menu.txt");
			} catch (IOException e) {
				System.err.println("ERROR: NO MENU FILE");
				System.exit(255);
			}
			s_Input = Console.consInput();

			try {
				i_Switch_Input = Integer.parseInt(s_Input);
			}

			catch (NumberFormatException i) {
				System.err.println("ERROR: WRONG INPUT");
			}

			switch (i_Switch_Input) {

			case 1:
				// Hier DepositAccount
				try {

					Bank.newDepositAccount(0, Console.getAccountName(), Console
							.getruntime(), Console.getlanguage(), Console
							.getcountry());

				} catch (NullPointerException ex) {
					System.out.println("Nullpoint");
				}
				break;

			case 2:
				// Hier GiroAccount
				try {

					Bank.newGiroAccount(0, Console.getAccountName(), Console
							.getcreditrating(), Console.getlanguage(), Console
							.getcountry());

				} catch (NullPointerException ex) {
					System.out.println("Nullpoint");
				}
				break;

			case 9:
				// Back to main menu
				b_Breakout = true;
				break;

			// ##### Wrong Case #####
			default:
				System.err.println("ERROR: WRONG NUMBER INSERTED");
				break;
			}
		} while (b_Breakout == false);
	}

}
